using System;
using PointOfSale.Global;
using System.Data;
using System.Data.SqlClient;

namespace PointOfSale.Class
{
	public class clsRate
	{
		private int itemId;
		private int unitId;
		private double rate;

		public clsRate()
		{
		}

		#region Properties
		public int ItemId
		{
			get
			{
				return itemId;
			}
			set
			{
				itemId = value;
			}
		}
		public int UnitId
		{
			get
			{
				return unitId;
			}
			set
			{
				unitId = value;
			}
		}
		public double Rate
		{
			get
			{
				return rate;
			}
			set
			{
				rate = value;
			}
		}
		#endregion
		public void Add()
		{
			String strInsert = "INSERT tblRate(ItemId, UnitId,Rate) " + 
				"VALUES("		+	 
				itemId			+ ", " + 
				unitId			+ ", " + 
				rate			+ ")";
			clsDatabase.ExecuteSQL(strInsert, clsGlobal.g_DataConn);
		}

		public void delete(string deleteCommand)
		{
			clsDatabase.ExecuteSQL(deleteCommand, clsGlobal.g_DataConn);
		}	
		
		public static double GetRate(int intItemId, int intUnitId)
		{
			string selectCommand="select rate from tblRate where itemId=" + intItemId + "and unitId=" + intUnitId;
			DataTable dt = clsDatabase.GetDataToTable(selectCommand, clsGlobal.g_DataConn);
			if(dt.Rows.Count>0)
			{
				return Convert.ToDouble(dt.Rows[0]["rate"].ToString());
			}
			else
			{
				return 0;
			}
		}
	}
}
